﻿using ComposantRefentielV2.BLL;
using GeneralServices.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Models.Utilisateur
{
    public class BLLUtilisateur : IBLLReferentiel
    {
        #region Attribut(s)
        
        #endregion

        #region Propriété(s)

        public BaseRepository<PV_UTILISATEUR> DAO { get; set; }

        #endregion

        #region Constructeur(s)

        public BLLUtilisateur(BaseRepository<PV_UTILISATEUR> repository)
        {
            DAO = repository;
        }

        #endregion

        #region IBLLReferentiel Membres

        public GeneralServices.Model.IDTO CreateElement()
        {
            return DAO.CreateEmpty();
        }

        public IEnumerable<System.Data.Entity.Validation.DbEntityValidationResult> GetValidationErrors()
        {
            return DAO.ContextBDD.GetValidationErrors();
        }

        public int Remove(object element)
        {
            if (element is IDTO)
                return DAO.Delete(element as IDTO);
            return 0;
        }

        public void RollBack()
        {
            DAO.RollBackAll();
        }

        public int SaveChanges(List<GeneralServices.Model.IDTO> list)
        {
            try
            {
                foreach (IDTO dto in list)
                    DAO.Save(dto);

                return DAO.UnitOfWork.Commit();
            }
            catch { throw; }
        }

        public List<GeneralServices.Model.IDTO> SelectAllBusiness()
        {
            List<IDTO> l = DAO.All().ToList<IDTO>();
            return l;
        }

        #endregion
    }
}
